package com.example.springannotation.controller;

import com.example.springannotation.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/test")
@RestController
public class TestController {
    @RequestMapping("/getFile")
    public String getFile(@RequestPart("file")MultipartFile multipartFile) throws IOException {
        // 获取文件名
        String fileName = multipartFile.getOriginalFilename();
        // 将文件上传到指定路径
        multipartFile.transferTo(new File("D:/" + multipartFile.getOriginalFilename()));
        return "接收到文件:" + fileName;
    }


    @RequestMapping("/getArray")
    public String getArray(String[] array) {
        return Arrays.toString(array);
    }
    @RequestMapping("/getList")
    public String getList(List<String> list) {
        return "接收到参数list" + list;
    }

    @RequestMapping("/getInt")
    public String getInt(int age) {
        return "接收到参数age: " + age;
    }
    @RequestMapping("/getInteger")
    public String getInt(Integer age) {
        return "接收到参数age: " + age;
    }

    @RequestMapping("/getBoolean")
    public String getBoolean(boolean b) {
        return "接收到参数b: " + b;
    }

    @RequestMapping("/getStudent")
    public String getStudent(@RequestBody Student student) {
        return "接收到参数student: " + student;
    }



  /*  @RequestMapping("/getChar")
    public String getChar(char c) {
        return "接收到参数c: " + c;
    }
    @RequestMapping("/getFloat")
    public String getFloat(float f) {
        return "接收到参数f: " + f;
    }

   */


}
